﻿package com.colorpicker{
	/**
	This class is used to create buttons
	
	@author Sharwan Kami <sharwan@gmail.com>
	@version 1.0
	@history 2009-05-10
	
	* 
	* This file is part of E-Card plugin, from zetaprints.com
	* 
	
	@usage
	Activate with:
		<code>
			//create the instance of the ZButton
			btnSelect=new ZButton("Select");
			btnSelect.x=10;
			btnSelect.y=20;
			btnSelect.addEventListener(MouseEvent.CLICK,onBtnClick);
			addChild(btnSelect);
		</code>
	
	*/
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormatAlign;
	import flash.text.TextFormat;
	import flash.events.MouseEvent;
	
	public class ZButton extends MovieClip{
		private var bHeight=20;//button height
		private var bWidth=50;//button width
		
		private var bg:MovieClip;//transparent background to fix mouse events
		
		private var txtLabel:String="";//button label (e.g. select/close etc)
		private var txtField:TextField;//textfield to display the label
		
		/**
			Constructor
		*/
		function ZButton(str:String){
			txtLabel=str;
			init();
			this.buttonMode=true;
			//following listeners are added if we need to add rollover/rollout effects
			//but currently not being used
			addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
			addEventListener(MouseEvent.ROLL_OVER,onMouseRollOut);
		}
		
		/**
		creates the components of the button and adds
		*/
		private function init():void{
			//create text field
			txtField = new TextField();
			txtField.selectable=false;
			txtField.border=true;
			txtField.borderColor=0xffffff;
			txtField.background=true;
			
			txtField.backgroundColor=0x323639;
			
			var format:TextFormat = new TextFormat();
            format.font = "Verdana";
            format.color = 0xffffff;
            format.size = 12;
			format.bold=true;
			format.align=TextFormatAlign.CENTER;
            txtField.defaultTextFormat = format;

            txtField.width = bWidth; 
			txtField.height = bHeight;
			txtField.text =txtLabel;
            addChild(txtField);
			
			//following movieclip is added on the top just to make the whole button clickable
			//keeping the textfield beneath it, so that event target can be determined easily
			bg=new MovieClip();
			bg.graphics.beginFill(0x323639,0);
			bg.graphics.drawRect(1,1,bWidth,bHeight);
			bg.graphics.endFill();			
			addChild(bg);
		}
		
		private function onMouseRollOver(e:MouseEvent):void{

		}
		private function onMouseRollOut(e:MouseEvent):void{

		}
	}
}